package com.testapp.bluetoothtest08.Controller;

import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.content.Intent;

public class BlueToothController {
    private BluetoothAdapter mAdapter;

    //获得本机的蓝牙适配器
    public BlueToothController() {
        this.mAdapter = BluetoothAdapter.getDefaultAdapter();
    }

    //打开蓝牙
    public void turnOn(){
        if(!mAdapter.isEnabled()){
            mAdapter.enable();
        }
    }

    //设置蓝牙可见
    public void setVisible(Context context){
        Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        intent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION,500);
        context.startActivity(intent);
    }

    //查找附近设备
    public void find(){
        mAdapter.startDiscovery();
    }

    //给蓝牙赋值编码
    public void setName(String code){
        mAdapter.setName(code);
    }

}
